<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="/common/taglibs.jsp"%>
<html>
  <head>
    
    <title>栏目模块管理</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<link rel="stylesheet" href="${ctx }/js/dtree/dtree.css" type="text/css" media="screen" />
	<script type="text/javascript" src="${ctx}/js/dtree/dtree.js"></script>
	<script type="text/javascript">
	
	
		function ajaxForm(){
		
	   		var taxis = $("#taxis").val();
	   		var name = $("#name").val();
	   		var url = $("#url").val();
	   		var permissionUrl = $("#permissionUrl").val();
	   		var remark =  $("#remark").val();
	   		var status =  $("#status").val();
	   		var parentID =  $("#parentID").val();
	   		var id =  $("#id").val();
		   	
	   		if(!checkNumber(taxis)){
	   			alert("排序号必须为数字");
	   			$("#taxis").focus();
	   			return false;
	   		}else if(checkIsNull(name)){
	   			alert("模块名称不能为空");
	   			$("#name").focus();
	   			return false;
	   		}else if(checkIsNull(url)){
	   			alert("url链接不能为空");
	   			$("#url").focus();
	   			return false;
	   		}
	   		
		   	var data  ={
		   		"res.id":id,
		   		"res.taxis":taxis,
		   		"res.name":name,
		   		"res.url":url,
		   		"res.permissionUrl":permissionUrl,
		   		"res.remark":remark,
		   		"res.status":status,
		   		"res.parentID":parentID
		   	};
		   	$.ajax({
				type: "POST",
				url: "${ctx}/pages/res/save.action",
				data: data,
				success: function(res) {
					alert("保存成功！");
					window.location.reload();	
				}
			});
       }
       
       function delRes(){
       
       		var resid = $("input[name='checkRes']:checked").val(); 
			if(confirm("您确定删除吗？")){
				$.ajax({
				    type: "POST",
					url: "${ctx}/pages/res/delete.action",
					data:{'id':resid},
					dataType:"json",
					success: function(data){
	     		 		if(data.result=="success"){
	     		 			window.location.reload(); 
	     		 		}
	     		 	}
	     		 });
			}			
		}
		
		function bethDelRes(){
			var ids = "";
				$("input[name='cbox']").each(function(){
					if($(this).is(":checked")){
						ids = ids + $(this).val()+",";
					}					
				});
				if(ids==""){
				  alert("请选择要删除的模块");
				  return ;
				}
			if(confirm("您确定删除吗？")){
				$.ajax({ 
				    type: "POST",
					url: "${ctx}/pages/res/delete.action",
					data:{'ids':ids},
					dataType:"json",
					success: function(data){
	     		 		if(data.result=="success"){
	     		 			window.location.reload(); 
	     		 		}
	     		 	}
	     		 });
			}			
		}
	
		function editInfo(){
		
			var id = $("input[name='checkRes']:checked").val(); 
			if(!checkIsNull(id)){
				var data  ={
		   			"id":id,
		   			"math":Math.random()
		   		};
		   		
				$.ajax({
					type: "GET",
					url: "${ctx}/pages/res/edit.action",
					data: data,
					success: function(res) {
						$("#id").val(res.id);
						$("#taxis").val(res.taxis);
				   		$("#name").val(res.name);
				   		$("#url").val(res.url);
				   		$("#permissionUrl").val(res.permissionUrl);
				   		$("#remark").val(res.remark);
				   		$("#status").val(res.status);
				   		$("#menuLab").click();
				   		$("#menuLab").text("修改栏目");
					}
				});
			}else{
				alert("请选择对象");
			}
		}
	</script>
  </head>
  <body>
    <div id="body-wrapper">
   		<div id="main-content">
			      <div class="content-box column-left">
			      <div class="content-box-header">
			        <h3 style="cursor: s-resize;">系统栏目列表</h3>
			      </div>
			      <!-- End .content-box-header -->
			      <div style="display: block;" class="content-box-content">
			        <div style="display: block;" class="tab-content default-tab">
			       
			        	<script type="text/javascript">
				         	d = new dTree('d','${ctx}/js/dtree/');
				         	d.add(0,-1,'系统模块','javascript:callback(0);');
				         	<c:forEach items="${menuTree}" var="res">
			        			d.add(${res.id},${res.parentID},'${res.name}','javascript:callback(${res.id});');
			       			</c:forEach>
				         	document.write(d);
				         	
				         	function callback(parentId){
				         		document.location.href = "${ctx}/pages/res/resList.action?parentId="+parentId;
					        }
			         	</script>
			        </div>
			        <!-- End #tab3 -->
			      </div>
			      <!-- End .content-box-content -->
			    </div>
			    
			    <div class="content-box column-right">
			      <div class="content-box-header">
			        
			        <h3 style="cursor: s-resize;">系统模块列表</h3>
			        <ul class="content-box-tabs">
			          <li><a href="#tab1" class="default-tab">模块列表</a></li>
			          <!-- href must be unique and match the id of target div -->
			          <li><a href="#tab2" id="menuLab">添加栏目</a></li>
			        </ul>
			        <div class="clear"></div>
			      </div>
			      <!-- End .content-box-header -->
			      <div style="display: block;" class="content-box-content">
			        <div style="display: block;" class="tab-content default-tab"  id="tab1">
			           <table>
				            <thead>
				            <tr>
				                <td colSpan="5">
				                  <a class="button" href="javascript:void(0);" onclick="editInfo();">修改</a>
				                  <a class="button" href="javascript:void(0);" onclick="delRes();">删除</a>
				                  <div class="clear"></div>
				                </td>
				              </tr>
				              <tr>
				                <th>排序</th>
				                <th>模块名称</th>
				                <th>模块连接</th>
				                <th>模块状态</th>
				                <th>创建时间</th>
				              </tr>
				            </thead>
				            <tbody>
				             <c:choose>
				             	<c:when test="${!empty menuList}">
					              <c:forEach items="${menuList}" var="menu" varStatus="i">
					              	<tr <c:if test="${i.count%2!=0}">class="alt-row"</c:if> >
					                <td>
					                  <input type="radio" name="checkRes" value="${menu.id}" >${menu.taxis}、
					                </td>
					                <td>${menu.name }</td>
					                <td>${menu.url }</td>
					                <td>
					                	<c:choose>
					                		<c:when test="${menu.status==1}">
					                			启用  
					                		</c:when>  
					                		<c:otherwise>  
					                			锁定   
					                		</c:otherwise>
					                	</c:choose> 
					                </td>
					                <td><fmt:formatDate value="${menu.createDate}"  pattern="yyyy-MM-dd"/></td>
					              </tr>
					              </c:forEach>
				              	</c:when>
				              	<c:otherwise>
				              		<tr>
				              			<td colspan="5" align="center">
				              					没有子栏目
				              			</td>
				              		</tr>
				              	</c:otherwise>
				              </c:choose>
				            </tbody>
				          </table>
			        </div>
			    
					    	<div class="tab-content" id="tab2">
					          <form action="#" method="post">
					            <fieldset>
									<p>
										<label>
											排序号
											<input value="" name="res.id" id="id" type="hidden">
											<input value="${parentId}" name="res.parentID" id="parentID" type="hidden">
										</label>
										<input id="taxis" class="text-input small-input"
											name="res.taxis" type="text">
									</p>
									
									<p>
										<label>
											模块名称
										</label>
										<input id="name" class="text-input small-input"
											name="res.name" type="text">
									</p>
									
									<p>
										<label>
											模块url
										</label>
										<input id="url" class="text-input small-input"
											name="res.url" type="text">
									</p>
									
									<p>
										<label>
											权限URL
										</label>
												
										<textarea class="text-input textarea " id="permissionUrl"
											name="res.permissionUrl" rows="8"></textarea>
									</p>
									
									<p>
										<label>
											备注
										</label>
										<textarea class="text-input textarea " id="remark"
											name="res.remark" rows="8"></textarea>
									</p>
									
									<p>
										<label>
											状态
										</label>
										<select class="small-input" name="res.status" id="status">
											<option  value="1">
												启用
											</option>
											<option value="0">
												锁定
											</option>
										</select>
									</p>
		
									<p>
										<input class="button" value="保 存" onclick="ajaxForm();"  type="button">
									</p>
								</fieldset>
					            <div class="clear"></div>
					          </form>
					        </div>
			        
			        
			      </div>
			      <!-- End .content-box-content -->
			    </div>
		</div>
	</div>
 </body>
</html>
